/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>微信支付相关配置</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <el-form ref="form" :model="form" label-width="200px" style="margin-top:20px">
      <el-divider content-position="left">商户配置</el-divider>
      <el-form-item label="商户号" prop="mch_id">
        <el-input v-model="form.mch_id" size="mini"></el-input>
        <p class="notic">商户号</p>
      </el-form-item>
      <el-form-item label="商户支付密钥" prop="key">
        <el-input v-model="form.key" size="mini"></el-input>
        <p class="notic">商户支付密钥</p>
      </el-form-item>
	  <el-form-item label="商户证书">
	  	<el-upload
	  	  class="upload-demo"
	  	  :action="apiHead + '/order/wx_pay/cert'"
	  	  :on-success="handleAvatarSuccess"
		  :headers="headers"
	  	  multiple
	  	  :limit="1"
	  	  :on-exceed="handleExceed"
	  	  :file-list="fileList">
	  	  <el-button size="small" type="primary">点击上传</el-button>
	  	</el-upload>
	  </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit()" :loading="isLoading">确认提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth.js";
export default {
  data() {
    return {
	  fileList: [],
      form: {mch_id: '', key: ''},
	  headers: {
		  Authorization: 'Bearer' + getToken()
	  },
      isLoading: false
    };
  },
  created() {
    this.getMiniAppPay();
	this.getCertName();
  },
  methods: {
	handleAvatarSuccess(res, file) {
		if (res.status == 1) {
			this.$message.success("上传成功")
		} else {
			this.$message.error(res.msg)
		}
	},
	handleExceed(files, fileList) {
	  this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
	},
	getCertName() {
		var that = this;
		this.request.get("/order/wx_pay/cert_name").then(function(res) {
			if (res) {
				that.fileList.push({
					name: res
				})
			}
		})
	},
    getMiniAppPay() {
      var that = this;
      this.request.get("/order/wx_pay").then(function(res) {
		  if(res){
			   that.form = res;
		  }
      });
    },
    onSubmit() {
      var that = this;
      this.isLoading = true;
      this.request.post("/order/wx_pay", that.form).then(res => {
        if (res.status == 1) {
          that.$message.success("保存成功");
        } else {
          that.$message.error("保存失败,失败原因:" + res.msg);
        }
        that.isLoading = false;
      });
    }
  }
};
</script>
<style scoped>
>>> .el-input__inner {
  width: 300px;
}
.upload-demo{
	display: flex;
}
</style>
